﻿using System.Web.Mvc;
using SportsStore.Domain.Abstract;
using SportsStore.WebUI.Models;

namespace SportsStore.WebUI.Controllers
{
    public class AccountController:Controller
    {
        private readonly IAuthProvider _authProvider;

        public AccountController(IAuthProvider authProvider)
        {
            _authProvider = authProvider;
        }
        [HttpGet]
        public ViewResult Login()
        {
           return View(); 
        }

        public ActionResult Login(LoginViewModel loginViewModel, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var result = _authProvider.Authenticate(loginViewModel.UserName, loginViewModel.Password);
                if (result)
                {
                    return Redirect(returnUrl ?? Url.Action("Index", "Admin"));

                }
                ModelState.AddModelError("","用户名或密码错误！");
                return View(loginViewModel);
            }
            return View();


        }
    }
}